
    source("1.3.1 beta_est.R")
    source("1.3.2 alpha_est.R")

    IPW = function(x.pi, x.delta.d, x.delta, z, d, y, weights){
        
        pi.x.est  = predict(glm(z ~ x.pi - 1, family=binomial(link=logit),
                                weights = weights), 
                            type = "response")
        f.z.x.est = pi.x.est
        f.z.x.est[z==0] = 1 - pi.x.est[z==0]
        
        beta.est.sol = BetaEst(x.delta.d, z, d, f.z.x.est, weights)
        beta.est     = beta.est.sol$par
        delta.d.est  = tanh(x.delta.d %*% beta.est)
        
        Delta.est = sum( weights * y * (2*z-1) / ( f.z.x.est * delta.d.est )  ) /
            sum(weights)
        
        b.alpha.est = AlphaEst(x.delta, z, y, f.z.x.est, delta.d.est, weights)$par
        b.Delta.est = sum( weights * tanh(x.delta %*% b.alpha.est) ) / sum(weights)
        
        return(list(f.z.x.est=f.z.x.est, delta.d.est=delta.d.est,
                    beta.est=beta.est, Delta.est=Delta.est,
                    b.Delta.est = b.Delta.est))
                
    }